/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commons;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 *
 * @author xmarti
 */
public class UtilsLanguage {
        private static ResourceBundle resourceBundle;
	private static String currentBaseName;
	private static Locale currentLocale;
        
        public static synchronized  boolean setDefaultLenguage (String baseName ){
            currentBaseName=baseName;
            try{
                resourceBundle= ResourceBundle.getBundle(baseName,Locale.getDefault());
                return true;
            }catch (MissingResourceException mre){
                System.err.println(mre.getMessage());                
                return false; 
            }                                           
        }
        public static synchronized  boolean setDefaultLenguage (String baseName,Locale local){
            currentBaseName=baseName;
            try{
                resourceBundle= ResourceBundle.getBundle(baseName,local);
                return true;
            }catch (MissingResourceException mre){
                System.err.println(mre.getMessage());                
                return false; 
            }
        }
        
        public static String getMessage (String m){
            try{
                return resourceBundle.getString(m);
            }catch(MissingResourceException mre){
                return new String();
            }
        }
        
        public static String getCurrentBaseName(){
            return currentBaseName;
        }
        
        public static Locale getLocale(){
            return currentLocale;
        }
                
}
